﻿<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript">
function checkparam(){
	 var name = $("#roleName").val();
	 if($.trim(name).length<1 || name.length>25){
			alert("请输入1到25个字符的角色名!");
			return false;
	 }
}

function returnback(){
	javascript:history.back();	     
  }  
  
function selectchild(childid,name,up){
var name_split=childid.split(".");
var ul_size=0;
if(document.getElementById('ul_size_'+name)!=null){
ul_size=document.getElementById('ul_size_'+name).value;
}
if(document.getElementById(childid).checked==true){
document.getElementById(name_split[0]).checked=true;
if(document.getElementById(up)!=null){
document.getElementById(up).checked=true;
}
if(parseInt(ul_size)>0){
 for(i=1;i<=parseInt(ul_size);i++){
  if(document.getElementById(name+'.'+i).checked==false){
  document.getElementById(name+'.'+i).checked=true;
  var second_level=null;
  if(document.getElementById(name+'.'+i)!=null){
  second_level=document.getElementById(name+'.'+i).value;
  }
 
 var second_ul_size=0;
 if(second_level!=null){
 if(document.getElementById('ul_size_'+second_level)!=null){
  second_ul_size=document.getElementById('ul_size_'+second_level).value;
 }
  }
 
 if(parseInt(second_ul_size)>0){
  for(j=1;j<=parseInt(second_ul_size);j++){
  
  if(document.getElementById(second_level+'.'+j).checked==false){
  document.getElementById(second_level+'.'+j).checked=true;
  }
  }
 }
 } 

 }
 }
 }else{
 if(parseInt(ul_size)>0){
 for(i=1;i<=parseInt(ul_size);i++){
 if(document.getElementById(name+'.'+i).checked==true){
 document.getElementById(name+'.'+i).checked=false;
   var second_level=null;
  if(document.getElementById(name+'.'+i)!=null){
  second_level=document.getElementById(name+'.'+i).value;
  }
 
 var second_ul_size=0;
 if(second_level!=null){
 if(document.getElementById('ul_size_'+second_level)!=null){
  second_ul_size=document.getElementById('ul_size_'+second_level).value;
 }
  }
 if(parseInt(second_ul_size)>0){
  for(j=1;j<=parseInt(second_ul_size);j++){
  if(document.getElementById(second_level+'.'+j).checked==true){
  document.getElementById(second_level+'.'+j).checked=false;
  }
  }
 }
 } 

 }
 }
 }
 
}  
</script>
<script  type="text/javascript">
	function menu_tree(meval){
  		var obj=document.getElementById('ul'+meval);
  		var collapsed=document.getElementById('collapsed'+meval);
  		if (obj.style.display=='none'){ 
    		obj.style.display='';
    		$("#collapsed"+meval).removeClass("collapsed").removeClass("expanded").addClass("expanded");
  		} else{ 
  			obj.style.display='none';
  			$("#collapsed"+meval).removeClass("collapsed").removeClass("expanded").addClass("collapsed");
  		}
	}

	function menu_tree_unfold(meval){
  		var obj=document.getElementById(meval);
    	obj.style.display='';
	}

	function menu_tree_fold(meval){
  		var obj=document.getElementById(meval);
  		obj.style.display='none'
	}

var fold_flag=0;
function menu_tree_all(){
var ul_id=document.getElementsByName('ul_id');
if(fold_flag==0){
var you=$('span[name=arrow]');
 for(i=0;i<(you.length);i++){
     
                        $(you[i])
                        	.removeClass("collapsed")
                        	.removeClass("expanded")
                            .addClass("expanded") ;
                      
                   
                 
}
for(i=0;i<(ul_id.length);i++){
menu_tree_unfold(ul_id[i].value);
 
}
fold_flag=1;
$("#open_tree").text("全部关闭");
}else{

	var you=$('span[name=arrow]');
 for(i=0;i<(you.length);i++){
  
    
                      
                        $(you[i])
                       	 	.removeClass("expanded")
                       	 	.removeClass("collapsed")
                            .addClass("collapsed")
                            
                        ;
                  
                 
}


for(i=0;i<(ul_id.length);i++){
menu_tree_fold(ul_id[i].value);
}
fold_flag=0;
$("#open_tree").text("全部展开");
}

}


function select_all(){
var allowfunction=document.getElementsByName('role.functions');
for(i=0;i<(allowfunction.length);i++){
allowfunction[i].checked=true;
}
}
function cancel_all(){
var allowfunction=document.getElementsByName('role.functions');
for(i=0;i<(allowfunction.length);i++){
allowfunction[i].checked=false;
}
}
</script>
</head>
<body>
  <!--     主体从这开始    -->
  <div class="container">
  	<h2 class="tit">
  		<a href="${ctx}/iccRefundBatchUpload.action">添加公司</a>
  		<a href="${ctx}/company/function" class="current">公司授权</a>
  	</h2>
  	
<form action="<%=request.getContextPath()%>/iccRoleSave.inview" method="post" onsubmit="return checkparam();">
	 <table class="global_table" cellpadding="0" cellspacing="0"> 
	 	<c:forEach  items="${modules}" var="module">
	 		<tr> 
        		<th style="width:110px;">${module.name}</th> 
        		<td>
        			<c:forEach items="${module.functions}" var="function">
						<input class="checkbox"  type="checkbox" value='${function.id}' id="${function.id}" 
								name="functionIds" 
								onclick="selectchild('${module.id}','${module.id}','${module.id}')" />
						<label>${function.name}</label>
					&nbsp;&nbsp;&nbsp;
				</c:forEach>
        		</td>
      	 </tr>
      	 </c:forEach>
      </table>
	
	<br />
<center>
<table>
<tr align="center">
<td>
	<input type="hidden" id="namestatus" name="namestatus" value="0" />	
	<div class="btncenter">
	<input type="submit" id="confirm_btn" class="g_btn_blue" value="确 定" /> &nbsp; &nbsp; &nbsp; <input type="button" id="back_btn" class="g_btn_blue2" value="返 回"  onclick="returnback()" /></div>
</td>
</tr>
</table>
</center>
</form>
</div>
  <!--     主体 end    -->
  <!-- 统计代码 begin-->
  <!--统计代码 end-->
</body>
</html>
